package cn.wsalix.config;

import java.net.InetAddress;
import java.net.UnknownHostException;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.wsalix.constant.DataDefine;
import cn.wsalix.constant.Global;
import cn.wsalix.type.PushTypeEnum;

/**
 * @author jskyme
 * 
 */
@Service("appConfig")
@Data
@EqualsAndHashCode(callSuper = false, exclude = {})
@ToString(exclude = {})
public class AppConfig {

	private PushTypeEnum pushType = PushTypeEnum.jpush;

	@Value("${domain.name}")
	private String domainName;

	@Value("${nginx.port}")
	private String nginxPort;

	@Value("${app.path}")
	private String appPath;

	@Value("${site.theme.path}")
	private String siteTheme;

	@Value("${admin.theme.path}")
	private String adminTheme;

	@Value("${wx.redirect.uri}")
	private String wxRedirectUri;

	@Value("${ftl.path}")
	private String ftlPath;

	@Value("${save.file.path}")
	private String saveFilePath;

	@Value("${nginx.url}")
	private String nginx1;

	@Value("${defualt.avatar}")
	private String defualtAvatar;
	
	@Value("${defualt.image}")
	private String defualtImage;

	@Value("${temple.dir}")
	private String templeDir;// 模板存放目录
	
	public String getNginxUrl() {
		return nginx1;/*String.format(Global.HOST_PATH, getLocalIP(), "80",
				nginx);*/
	}
	
	public String getBackTheme() {
		return adminTheme;/*String.format(Global.HOST_PATH, getLocalIP(), "80",
				adminTheme);*/
	}

	public String getFrontTheme() {
		return siteTheme;//String.format(Global.HOST_PATH, getLocalIP(), "80",
				//siteTheme);
	}

	public String getHtmlOutPath() {
		return saveFilePath + "html";
	}

	public String getHttpPrix() {
		return getNginxUrl() + "/html";
	}

	//
	public static DataDefine sysPara = new DataDefine("sysPara", "系统参数");

	//
	public static DataDefine adCat = new DataDefine("adCat", "广告分类");
	public static DataDefine adBanner = new DataDefine("adBanner", "首页广告");

	public static DataDefine articleCat = new DataDefine("articleCat", "文章分类");
	public static DataDefine articleAd = new DataDefine("articleAd", "广告");
	public static DataDefine productCat = new DataDefine("productCat", "产品分类");

	private String getLocalIP() {
		InetAddress addr = null;
		try {
			addr = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		byte[] ipAddr = addr.getAddress();
		String ipAddrStr = "";
		for (int i = 0; i < ipAddr.length; i++) {
			if (i > 0) {
				ipAddrStr += ".";
			}
			ipAddrStr += ipAddr[i] & 0xFF;
		}
		return ipAddrStr;
	}

}
